package com.xuchy.service.impl;

import com.xuchy.entity.History;
import com.xuchy.mapper.HistoryMapper;
import com.xuchy.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * <li>文件名称: HistoryServiceImpl</li>
 * <li>文件描述: 无</li>
 * <li>创建日期： 2019/10/28 20:47</li>
 *
 * @author xuchy
 */
@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void insert() throws Exception {
        //模拟插入12个月数据，每个月存入对应月份的表
        for (int i = 1; i <= 12; i++) {
            History history = new History();
            history.setDescription("第" + i + "个月");
            history.setCreateTime(sf.parse("2019-" + (i < 10 ? ("0" + i) : i) + "-01 12:00:00"));
            historyMapper.insert(history);
            System.out.println("插入成功，id=====" + history.getId());
        }
    }

    @Override
    public List<History> queryList(Map<String, Object> params) {
        return historyMapper.queryList(params);
    }

}
